<?php
/**
 * Records
 * 
 * @package SFramework
 * @author Shuky
 * @since v1.0
 * @version $Id: Records.php 82 2010-12-23 18:23:35Z shukyoo@gmail.com $
 */
namespace SFramework\SAbstract;
use SFramework;

class Records implements \Iterator, \ArrayAccess, \Countable
{
	// 存储数组
	private $_data = array();


	public function __construct(array $data = array())
	{
		if (!empty($data)) {
			$this->_data = $data;
		}
	}

	public function addRecords(array $data)
	{
		$this->_data = array_merge($this->_data, $data);
	}

	public function __set($key, $value)
	{
		$this->_data[$key] = $value;
	}

	public function __get($key)
	{
		return isset($this->_data[$key]) ? $this->_data[$key] : null;
	}

	public function __isset($key)
	{
		return isset($this->_data[$key]);
	}

	public function __unset($key)
	{
		unset($this->_data[$key]);
	}


	/**
	 * ----- Iterator -----
	 */
	public function current()
	{
		return current($this->_data);
	}

	public function key()
	{
	}

	public function next()
	{
		next($this->_data);
	}

	public function rewind()
	{
	}

	public function valid()
	{
	}


	/**
	 * ----- ArrayAccess -----
	 */
	public function offsetExists($key)
	{
	}

	public function offsetGet($key)
	{
	}

	public function offsetSet($key, $value)
	{
	}

	public function offsetUnset($key)
	{
	}

	/**
	 * ----- Countable -----
	 */
	public function count()
	{
		return count($this->_data);
	}
}

$records = new Records();

$records->tt = 1;
$records->aa = 2;
foreach ($records as $v) {
	echo $k ,':', $v ,'<br>';
}